package fr.univ.surveyonline.model;

import java.util.Calendar;

import org.junit.rules.ExpectedException;

import org.junit.*;

import static org.junit.Assert.*;

public class TestSurvey {

	// TESTED OBJECT
	private Survey survey;
	
	@Rule
	public ExpectedException thrown = ExpectedException.none();
	
	@Before
	public void setUp() {
		this.survey = new Survey();
	}
	
	@Test
	public void testSetSondeur_01_1() {
		thrown.expect(IllegalArgumentException.class);
		this.survey.setSondeur(null);
	}
	
	@Test
	public void testSetSondeur_01_2() {
		User user = new User();
		user.setRole(Role.MEMBRE);
		thrown.expect(IllegalStateException.class);
		this.survey.setSondeur(user);
	}
	
	@Test
	public void testSetSondeur_02() {
		User user = new User();
		user.setRole(Role.SONDEUR);
		this.survey.setSondeur(user);
		assertEquals(user, this.survey.getSondeur());
	}
	
	@Test
	public void testSetXml_01() {
		thrown.expect(IllegalArgumentException.class);
		this.survey.setXml(null);
	}
	
	@Test
	public void testSetXml_02() {
		// TODO
	}
	
	@Test
	public void testSetBeginDate_01() {
		thrown.expect(IllegalArgumentException.class);
		this.survey.setBeginDate(null);
	}
	
	@Test
	public void testSetBeginDate_02_1() {
		int year = 1987;
		int month = Calendar.JANUARY;
		int day = 27;
		Calendar date = Calendar.getInstance();
		date.set(year, month, day);
		this.survey.setBeginDate(date);
		assertEquals(date, this.survey.getBeginDate());
	}
	
	@Test
	public void testSetBeginDate_02_2() {
		int year = 1980;
		int month = Calendar.DECEMBER;
		int day = 3;
		Calendar date = Calendar.getInstance();
		date.set(year, month, day);
		this.survey.setBeginDate(date);
		assertEquals(date, this.survey.getBeginDate());
	}
	
	@Test
	public void testSetBeginDate_02_3() {
		int year = 2008;
		int month = Calendar.NOVEMBER;
		int day = 6;
		Calendar date = Calendar.getInstance();
		date.set(year, month, day);
		this.survey.setBeginDate(date);
		assertEquals(date, this.survey.getBeginDate());
	}
	
	@Test
	public void testSetEndDate_01() {
		thrown.expect(IllegalArgumentException.class);
		this.survey.setEndDate(null);
	}
	
	@Test
	public void testSetEndDate_02_1() {
		int year = 2010;
		int month = Calendar.JULY;
		int day = 11;
		Calendar date = Calendar.getInstance();
		date.set(year, month, day);
		this.survey.setEndDate(date);
		assertEquals(date, this.survey.getEndDate());
	}
	
	@Test
	public void testSetEndDate_02_2() {
		int year = 2011;
		int month = Calendar.MARCH;
		int day = 5;
		Calendar date = Calendar.getInstance();
		date.set(year, month, day);
		this.survey.setEndDate(date);
		assertEquals(date, this.survey.getEndDate());
	}
	
	@Test
	public void testSetEndDate_02_3() {
		int year = 2012;
		int month = Calendar.FEBRUARY;
		int day = 23;
		Calendar date = Calendar.getInstance();
		date.set(year, month, day);
		this.survey.setEndDate(date);
		assertEquals(date, this.survey.getEndDate());
	}
	
}
